from datetime import datetime

from sqlalchemy import Column, Integer, String
from sqlalchemy.dialects.mysql import LONGTEXT
from app.libs.tools import get_key_words
from app.libs.TextRank.textRank import TextRank
from app.models.base import Base, db
from app import redisclient
from app.config.setting import *

class Paragraphs(Base):
    id = Column(Integer, primary_key=True, autoincrement=True)
    order_number = Column(String(30), nullable=False)
    paragraph_index = Column(Integer, nullable=False)
    content = Column(LONGTEXT, default='')

    @staticmethod
    def insert_paragrahs(contents, order_number):
        params = []
        index = 0
        now = int(datetime.now().timestamp())
        for paragraph in contents:
            if paragraph == '':
                paragraph = ' '
            params.append(
                {
                    'create_time': now,
                    'status': 1,
                    'order_number': order_number,
                    'paragraph_index': index,
                    'content': paragraph
                }
            )
            index += 1
        db.engine.execute(Paragraphs.__table__.insert(), params)
